/**
 * search页面的一些api
 */
import request from '@/config/axios'

export const getC2ListByC1Id = (c1Id, c3Id = '', keyword = '') => {
  console.log({ c1Id, c3Id, keyword })
  return request.get({
    url: `/g_data/api/v1/sale/good_usage_category/getForoneYCategoryByUsageId?usage_category_id=${c1Id}&x_category_id=${c3Id}&keyword=${keyword}`
  })
}

export const getC2ListByC1IdV2 = (c1Id) => {
  return request.get({
    url: `/api/onlyforone/colorAtlasProduct/getColorAtlasCategory?id=${c1Id}`
  })
}

export const getC3ListByC1IdAndC2Id = (c1Id, c2Id = '', keyword = '') => {
  console.log({ c1Id, c2Id, keyword })
  return request.get({
    url: `/g_data/api/v1/sale/good_usage_category/getForoneXCategoryByUsageId`,
    params: {
      usage_category_id: c1Id,
      y_category_id: c2Id ?? '',
      keyword
    }
  })
}

export const pageGood = (queryWrapper) => {
  let realQeryWrapper = {}
  realQeryWrapper.usage_category_id = queryWrapper.c1Id
  if (queryWrapper.c2Id) {
    realQeryWrapper.y_category_id = queryWrapper.c2Id
  }
  if (queryWrapper.c3Id) {
    realQeryWrapper.x_category_id = queryWrapper.c3Id
  }
  if (queryWrapper.pageSize) {
    realQeryWrapper.page_size = queryWrapper.pageSize
  }
  if (queryWrapper.pageNumber) {
    realQeryWrapper.page = queryWrapper.pageNumber
  }

  if (queryWrapper.keyword) {
    realQeryWrapper.keyword = queryWrapper.keyword
  }
  // debugger

  Object.keys(realQeryWrapper).forEach((key) => {
    if (realQeryWrapper[key] == undefined) {
      delete realQeryWrapper[key]
    }
  })

  return request.get({
    url: `/g_data/api/v1/sale/goodsMainCategoryCombo/getForoneGoods`,
    params: realQeryWrapper
  })
}

export const v2_pageGood = (queryWrapper) => {
  let realQeryWrapper = {}
  // realQeryWrapper.usage_category_id = queryWrapper.c1Id
  if (queryWrapper.c2Id) {
    realQeryWrapper.level_two_category_id = queryWrapper.c2Id
  }
 
  if (queryWrapper.pageSize) {
    realQeryWrapper.page_size = queryWrapper.pageSize
  }
  if (queryWrapper.pageNumber) {
    realQeryWrapper.page = queryWrapper.pageNumber
  }

  if (queryWrapper.keyword) {
    realQeryWrapper.keyword = queryWrapper.keyword
  }
  // debugger

  Object.keys(realQeryWrapper).forEach((key) => {
    if (realQeryWrapper[key] == undefined) {
      delete realQeryWrapper[key]
    }
  })

  console.log(realQeryWrapper)
  return request.get({
    url: `/api/onlyforone/colorAtlasProduct/v1/search`,
    params: realQeryWrapper
  })
}
export const collectGood = (goodId) =>
  request.post({
    url: `/api/onlyforone/collection/add`,
    params: {
      goods_id: goodId
    }
  })

export const cancelCollectGood = (goodId) =>
  request.delete({
    url: `/api/onlyforone/collection/delete/${goodId}`,
    params: {
      goods_id: goodId
    }
  })


  export const collectColorAtlasProduct = (goodId) =>
    request.post({
      url: `/api/onlyforone/colorAtlasProductCollection/add`,
      params: {
        goods_id: goodId
      }
    })
  
  export const cancelCollectColorAtlasProduct = (goodId) =>
    request.delete({
      url: `/api/onlyforone/colorAtlasProductCollection/delete/${goodId}`,
      params: {
        goods_id: goodId
      }
    })